package com.unohacha.qqj.fzdr.personal.view.activity;

import android.app.Activity;
import android.graphics.Bitmap;
import android.net.http.SslError;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.RequiresApi;
import android.view.View;
import android.webkit.SslErrorHandler;
import android.webkit.WebResourceRequest;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import android.widget.TextView;

import com.unohacha.qqj.fzdr.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

//需要联网
public class WebViewHomeActivity extends Activity
//        implements ActionBarClickListener
{

    @BindView(R.id.about_us_webview)
    WebView aboutUsWebview;
    @BindView(R.id.common_back)
    ImageView commonBack;
    @BindView(R.id.common_title)
    TextView commonTitle;
    @BindView(R.id.common_right_image)
    ImageView commonRightImage;
    //    @BindView(R.id.actionbar)
//    TranslucentActionBar actionbar;
    private String url;
    private String title;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_webview_home);
        ButterKnife.bind(this);
//        String title = getIntent().getStringExtra("title");

        commonRightImage.setVisibility(View.INVISIBLE);
        url = getIntent().getStringExtra("url");
        title = getIntent().getStringExtra("title");
        commonTitle.setText(title);
//        actionbar.setData(title, R.drawable.ic_lefft_white, null, 0, null,0, this);
//        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
//            this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
//            actionbar.setStatusBarHeight(getStatusBarHeight());
//        }

        WebSettings webSettings = aboutUsWebview.getSettings();
        webSettings.setJavaScriptEnabled(true);//如果访问的页面中要与Javascript交互，则webview必须设置支持Javascript
        webSettings.setAllowFileAccess(true); //设置可以访问文件
        webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);//解决字符串换行问题
        webSettings.setUseWideViewPort(true); // 设置此属性，可任意比例缩放。
        webSettings.setBuiltInZoomControls(true);  // 设置是否可缩放
        webSettings.setLoadWithOverviewMode(true);
        webSettings.setSupportZoom(true);  //缩放开关
        webSettings.setDefaultFontSize(28);
        webSettings.setDefaultTextEncodingName("UTF-8");
//        WebSettings wSet = aboutUsWebview.getSettings();
//        wSet.setJavaScriptEnabled(true);
//        getData();
        aboutUsWebview.setWebViewClient(new WebViewClient() {
            @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
            public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
                view.loadUrl(String.valueOf(request.getUrl()));
                return true;
            }

            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                //重写此方法表明点击网页在当前的webview跳转,不跳到浏览器中
                view.loadUrl(url);
                return true;
            }

            public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
//                        //接受证书
                handler.proceed();
            }

            @Override
            public void onPageStarted(WebView view, String url, Bitmap favicon) {
                super.onPageStarted(view, url, favicon);
            }

        });
        //查看页面
        aboutUsWebview.loadUrl(url);

    }

    @OnClick(R.id.common_back)
    public void onViewClicked() {
        finish();
    }


//    private void getData(){//获取url
//                        aboutUsWebview.loadUrl(url);
//       }

//    @Override
//    public void onLeftClick() {
//        finish();
//    }
//
//    @Override
//    public void onRightClick() {
//
//    }
//
//    @Override
//    public void onEditTextClick() {
//
//    }
}
